package com.tnsw.noxnox.signin;

import com.tnsw.noxnox.R;

import android.content.Context;
import android.graphics.Canvas;
import android.text.style.LineHeightSpan.WithDensity;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.view.View.OnClickListener;

public class NXViewSwitcher extends RelativeLayout implements OnClickListener {

	private String tag = "NXViewSwitcher";
	private LayoutInflater inflater;
	private TextView tvTitle, tvDescription;
	private Switch switchPush;
	private View v;
	private Context context;
	private boolean workAroundMode = false;
	
	
	public NXViewSwitcher(Context context) {
		super(context);
		this.context = context;

	}
	
	public NXViewSwitcher(Context context, AttributeSet attrSet) {
		super(context, attrSet);
		this.context = context;
	}
	
	public NXViewSwitcher(Context context, View v) {
		super(context);
		this.workAroundMode = true;
		this.v = v;
		this.initialize();
	}
	
	public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
		this.switchPush.setOnCheckedChangeListener(listener);
	}
	
	protected void onFinishInflate() {
		Log.d(tag, "onFinishInflate()");
		super.onFinishInflate();
		
		if (!(this.workAroundMode)) {
			this.inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			this.v = this.inflater.inflate(com.tnsw.noxnox.R.layout.base_switcher, this);
			this.initialize();			
		}

	}
	
	private void initialize() {
		
		this.tvTitle = (TextView) v.findViewById(R.id.tvTitle);
		this.tvDescription = (TextView) v.findViewById(R.id.tvDescription);
		this.switchPush = (Switch) v.findViewById(R.id.switchPush);
		this.switchPush.setFocusable(false);
		this.switchPush.setFocusableInTouchMode(false);
		
		
		//this.v.setOnClickListener(this);
		
	}
	
	public void test() {
		this.tvTitle.setText("Hello workaround :-(");
	}

	@Override
	public void onClick(View v) {
		Log.d(tag, "onClick()");

		
	}

}
